package com.hxit.huaxiamelongarden.service.impl;

import com.hxit.huaxiamelongarden.domin.dto.LikeDto;
import com.hxit.huaxiamelongarden.domin.po.Content;
import com.hxit.huaxiamelongarden.domin.po.Like;
import com.hxit.huaxiamelongarden.mapper.ContentMapper;
import com.hxit.huaxiamelongarden.mapper.LikeMapper;
import com.hxit.huaxiamelongarden.service.LikeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

import static java.util.stream.Collectors.toList;

/**
 * @ClassName LikeServiceImpl
 * @description 点赞逻辑实现类
 * @Author 12694
 * @Date 2025/1/28 11:54
 * @Version 1.0
 **/
@Service
public class LikeServiceImpl implements LikeService {
    @Autowired
    private LikeMapper likeMapper;
    @Autowired
    private ContentMapper contentMapper;

    /*查询用户的点赞列表*/
    @Override
    public LikeDto selectLikesByUserId(Integer userId) {
        List<Like> likes = likeMapper.selectLikesByUserId(userId);
        List<Content> contents = likes.stream().map(like -> {
            Content contentPo = contentMapper.getCommentsByContentId(like.getContentId());
            return contentPo;
        }).collect(toList());
        LikeDto likeDto = new LikeDto();
        likeDto.setContentList(contents);
        return likeDto;
    }
}
